﻿using System;
using System.Windows;

namespace Genetic
{
    public partial class frmFileType : Window
    {
        public int FileTypeIndex { get; set; }

        public frmFileType(string filePath)
        {
            InitializeComponent();

            if (!string.IsNullOrEmpty(filePath))
            {
                txtPath.Text = filePath;
                txtPath.CaretIndex = 0;
            }
            else
            {
                lblPath.Visibility = Visibility.Collapsed;
                txtPath.Visibility = Visibility.Collapsed;
                Height -= 35;
            }

            //set available file types
            FileTypeItem[] typeItems = new FileTypeItem[Helper.Template.Data.Files.Count];
            for (int i = 0; i < Helper.Template.Data.Files.Count; i++)
            {
                typeItems[i] = new FileTypeItem
                    {
                        Name = Helper.Template.Data.Files[i].Name,
                        Index = i
                    };
            }

            cmbType.ItemsSource = typeItems;

            if (cmbType.Items.Count > Helper.Settings.Data.Data.Forms.ChooseFileType.SelectedFileType)
            {
                cmbType.SelectedIndex = Helper.Settings.Data.Data.Forms.ChooseFileType.SelectedFileType;
            }
            else
            {
                cmbType.SelectedIndex = 0;
            }
        }

        void Window_Closed(object sender, EventArgs e)
        {
            FileTypeIndex = ((FileTypeItem)cmbType.SelectedItem).Index;
            Helper.Settings.Data.Data.Forms.ChooseFileType.SelectedFileType = cmbType.SelectedIndex;
        }

        void btnOK_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }
    }

    public class FileTypeItem
    {
        public string Name;
        public int Index;

        public override string ToString()
        {
            return Name;
        }
    }
}
